<template>
	<view>
		<!-- 顶部导航 -->
		<fa-navbar :title="title" :border-bottom="false"></fa-navbar>
		<view class="u-p-30 bg-white">
			<u-form :model="form" ref="uForm" label-width="180">
				<!-- <u-form-item label="产品名称" prop="coupname">
					{{form.coupname}}
				</u-form-item> -->
				<!-- <u-form-item label="有效时间" prop="createtimerange">
					<u-input v-model="form.createtimerange" />
				</u-form-item> -->
				<u-form-item label="姓名" prop="realname">					
					{{form.username}}
				</u-form-item>
				<u-form-item label="手机" prop="mobile">
					{{form.mobile}}
				</u-form-item>
			<!-- 	<u-form-item label="余额" prop="numstotal">
					{{form.numstotal}}
				</u-form-item> -->
			
				<u-form-item label="余额" prop="money">
					{{form.money}}
				</u-form-item>
				
				<u-form-item label="支付金额" prop="price">
					<u-input v-model="form.needpay" type="number"/>
					
				</u-form-item> 
						
			<!-- 	<u-form-item label="核销码" prop="verifiycode">
					{{form.verifiycode}}
				</u-form-item> -->
				<!-- <u-form-item label="日期" prop="ydtime"  @click="toBooking()">
					<u-input v-model="form.ydtime" />
				</u-form-item>
				
				 -->
				<!-- <u-form-item label="所在地区" prop="area_name">
					<u-input type="select" :select-open="cityShow" v-model="form.area_name" placeholder="请选择地区" @click="cityShow = true"></u-input>
				</u-form-item> -->
				<!-- <u-form-item label="详细地址" prop="address">
					<u-input type="textarea" v-model="form.address" />
					<u-button slot="right" type="primary" :custom-style="{ backgroundColor: theme.bgColor, color: theme.color }" size="mini" @click="chooseAddress">
						选择地址
					</u-button>
				</u-form-item> -->
			</u-form>
		</view>
		
		<!-- 预订日历 -->
	 
		<!-- 城市 -->
		 <view class="footer-bar u-flex u-col-center u-row-center u-border-top">
			<u-button type="primary" :custom-style="{ width: '80vw', backgroundColor: '#007eff', color: theme.color }" shape="circle" hover-class="none" @click="sumbit">
				提交支付
			</u-button>
		</view>
	</view>
</template>

<script>
export default {
	
	data() {
		return {
			title: '详情',
			form: {
				receiver: '',
				mobile: '',
				address: '',
				isdefault: 1,
				area_name: '',
				area_id: '',
				createtimerange:'',
				nums:'',
				usetimes:'',
				numstotal:''
				
				
			},
			rules: {				 
				mobile: [
					{
						validator: (rule, value, callback) => {
							return this.$u.test.mobile(value);
						},
						message: '手机号码不正确',
						// 可以单个或者同时写两个触发验证方式
						trigger: ['change', 'blur']
					}
				] 
			},
			isdefault: false,
			cityShow: false,
			is_render: false,
			areaCode: [],
			goods_info: {},
			is_show: 0,
			value: false,
			oid:0,
			verifiycode:'',
			uid:''
		};
	},
	onLoad(options) {
		
			// this.goPage('/pages/uform/verificoupdetail?vercode=' + res.data.verifiycode+'&uid='+res.data.user_id);
			
		console.log(options);	
		
		  if (this.getUrlParam("vercode", decodeURIComponent(options.scene))) {
			  //扫码进来带参数	 
					 this.verifiycode = this.getUrlParam("vercode", decodeURIComponent(options.scene)) || '';
					 this.uid = this.getUrlParam("uid", decodeURIComponent(options.scene)) || '';
		    }else if(options.q){
				const q = decodeURIComponent(options.q);
				this.verifiycode=this.getQueryString(q,'vercode') || '';
				this.uid=this.getQueryString(q,'uid') || '';	
			}else{
				this.verifiycode = options.vercode || '';
					this.uid = options.uid || '';
			} 
			
		console.log(this.verifiycode);
 
		
		// this.verifiycode = e.vercode || '';
	
		if (this.verifiycode) {
			this.title = '详情';
			this.getInfo();
		} else {
			this.title = '添加';
			this.is_render = true; 
		}
		// uni.setNavigationBarTitle({
		// 	title: this.title
		// });
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	
	methods: {
		getQueryString(url, name){
		    var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
		    var r = url.substr(1).match(reg)
		    if (r != null) {
		        return r[2]
		    }
		    return null;
		},
		getInfo() {
			 
			this.$api.getUinfocommon({ verifiycode: this.verifiycode,uid: this.uid, }).then(res => {
				if (res.code) {
					// this.form = Object.assign(this.form, {
					// 	id: this.id,
					// 	receiver: res.data.receiver,
					// 	mobile: res.data.mobile,
					// 	address: res.data.address
					// });
				 this.form =res.data;
				 console.log("sdfsdf",this.form);
				 
				} else {
					this.$u.toast(res.msg);
					// uni.$u.route({
					// 	type:'back'
					// });
				}
			});
		},
		getUrlParam(name, str) {
		        let regs = new RegExp("scene=", "g"); //场景值
		        str = str.replace(regs, ""); 
		        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		        var array = str.match(reg);
		        if (array != null)
		            return array[2];
	   },
		change(value) {
			this.form.isdefault = value ? 1 : 0;
		},
		chooseAddress() {
			uni.chooseLocation({
				success: res => {
					Object.assign(this.form, {
						address: res.address
					});
				}
			});
		},
		//城市选择
		cityResult(e) {
			this.form.area_name = e.province.label + '/' + e.city.label + '/' + e.area.label;
			this.form.area_id = e.area.value;
		},
		sumbit() {
			this.$refs.uForm.validate(valid => {
				if (valid) {
					// dealUsercredit verifiycoupup
					this.form.odtype="order";
					this.$api.dealUsercredit(this.form).then(res => {					
						
						if (res.code) {
							this.$u.toast(res.msg);
							// this.goPage('/pages/order/verificoupdetail?oid=' + res.data.id);
							setTimeout(() => {
								// windows.loc
								// location.reload();
								// this.$router.go(0)
								this.getInfo();
								// window.location.href=window.location.href;
								// uni.$u.route({
								// 	type:'back'
								// })
							}, 1500);
						}else{
					 
							this.$u.toast(res.msg);
						}
					});
				} else {
					console.log('验证失败');
				}
			});
		},
		toBooking() {
						this.goods_info = [{id:1,name:'111',price:1,calendar:'2024-06-26',order_calendar:'2024-06-20'},
						{id:2,name:'111',price:1,calendar:'2024-06-26',order_calendar:'2024-06-20'}];
						this.is_show = true;
						setTimeout(() => {
							this.value = true;
						}, 100);	
					},
					calendarConfirm(e, dom) {
						if (JSON.stringify(e) == '{}') {
							this.$u.toast('请选择入住和离店日期');
							return;
						}
						if (!dom) {
							return;
						}
						this.goPage('/pages/hotel/booking?id=' + this.goods_info.id + '&start_time=' + e.start + '&end_time=' + e.end);
					}
	}
};
</script>

<style lang="scss">
page {
	background-color: #f4f6f8;
}
</style>
